/**
 * Created by admin on 2017/4/19.
 */
$(function () {
    var codes = "";

    function loginHander(data) {

        if (data.starts) {
            window.location.href = "information_success.html";
        } else {
            alert("网络连接超时，请稍后再试！");
        }
    }

    function getPhoneAndNameHander(data) {
        if (data.starts != "0") {
            if (data.starts == "3") {
                alert(data.msg);
                window.location.href = "perfect_the_information.html";
            }
            window.location.href = "perfect_the_information.html";
        } else {
            alert(data.msg);
        }
    }

    $("#loginBtn").click(function () {
        var name = $("#userName").val();
        var phone = $("#userPhone").val();
        var code123 = util.GetQueryString("abc");
        localStorage.setItem("codes", code123);
        var name_return = util.isNull(name);
        var phone_return = util.phone(phone);
        if (name_return == 1) {
            if (phone_return == 1) {
                localStorage.setItem("userName", name);
                localStorage.setItem("userPhone", phone);
                $('.tishi').html("");
                var data = {
                    name: name,
                    phone: phone,
                    code: code123
                };
                util.ajax("submitPhoneAndName", data, getPhoneAndNameHander);
            } else {
                $('.tishi').html("*请准确输入电话号码!");
                $("#userPhone").val("").focus();
            }
        } else {
            $('.tishi').html("*请输入用户姓名!");
            $("#userName").val("").focus();
        }
    });
    $("#submitBtn").click(function () {

        var ageType = "";
        var houseType = "";
        var carType = "";
        $('input[name="age"]:checked').each(function () {
            ageType = $(this).val();
        });
        $('input[name="house"]:checked').each(function () {
            houseType = $(this).val();
        });
        $('input[name="car"]:checked').each(function () {
            carType = $(this).val();
        });
        var name = localStorage.getItem("userName");
        var phone = localStorage.getItem("userPhone");
        var code = localStorage.getItem("codes");
        localStorage.setItem("codes",code);
        var data = {
            name: name,
            phone: phone,
            age: ageType,
            house: houseType,
            car: carType,
            code: code
        };
        util.ajax("submitInformation", data, loginHander);
    });
    $("#iosClick").on("click", function () {

        var code = localStorage.getItem("codes");
        if (code == 'tuia2') {
            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.zqxq.jiekuanwang";
        } else {
            window.location.href = "https://itunes.apple.com/cn/app/借款王-有信用秒下10万的手机贷款借贷宝贝/id1136185453?mt=8";
        }
    });

    $("#andClick").on("click", function () {
        var code = localStorage.getItem("codes");
        if (code == 'tuia2') {
            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.zqxq.jiekuanwang";
        } else {
            window.location.href = "http://download.zhushou.sogou.com/open/files/year_2017/day_20170406/8ebe555263338a6df7793c0e87adfb99.apk";
        }
    });

});
